home *** CD-ROM | disk | FTP | other *** search
/ American Osteopathic Ass…tion Yearbook 2005 & 2006 / American Osteopathic Association Yearbook 2005 & 2006.iso / mac / app / string.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2004-07-22  |  14.5 KB  |  367 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.3)
  3.  
  4. """A collection of string operations (most are no longer used in Python 1.6).
  5.  
  6. Warning: most of the code you see here isn't normally used nowadays.  With
  7. Python 1.6, many of these functions are implemented as methods on the
  8. standard string object. They used to be implemented by a built-in module
  9. called strop, but strop is now obsolete itself.
  10.  
  11. Public module variables:
  12.  
  13. whitespace -- a string containing all characters considered whitespace
  14. lowercase -- a string containing all characters considered lowercase letters
  15. uppercase -- a string containing all characters considered uppercase letters
  16. letters -- a string containing all characters considered letters
  17. digits -- a string containing all characters considered decimal digits
  18. hexdigits -- a string containing all characters considered hexadecimal digits
  19. octdigits -- a string containing all characters considered octal digits
  20. punctuation -- a string containing all characters considered punctuation
  21. printable -- a string containing all characters considered printable
  22.  
  23. """
  24. whitespace = ' \t\n\r\x0b\x0c'
  25. lowercase = 'abcdefghijklmnopqrstuvwxyz'
  26. uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  27. letters = lowercase + uppercase
  28. ascii_lowercase = lowercase
  29. ascii_uppercase = uppercase
  30. ascii_letters = ascii_lowercase + ascii_uppercase
  31. digits = '0123456789'
  32. hexdigits = digits + 'abcdef' + 'ABCDEF'
  33. octdigits = '01234567'
  34. punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
  35. printable = digits + letters + punctuation + whitespace
  36. l = map(chr, xrange(256))
  37. _idmap = str('').join(l)
  38. del l
  39. index_error = ValueError
  40. atoi_error = ValueError
  41. atof_error = ValueError
  42. atol_error = ValueError
  43.  
  44. def lower(s):
  45.     '''lower(s) -> string
  46.  
  47.     Return a copy of the string s converted to lowercase.
  48.  
  49.     '''
  50.     return s.lower()
  51.  
  52.  
  53. def upper(s):
  54.     '''upper(s) -> string
  55.  
  56.     Return a copy of the string s converted to uppercase.
  57.  
  58.     '''
  59.     return s.upper()
  60.  
  61.  
  62. def swapcase(s):
  63.     '''swapcase(s) -> string
  64.  
  65.     Return a copy of the string s with upper case characters
  66.     converted to lowercase and vice versa.
  67.  
  68.     '''
  69.     return s.swapcase()
  70.  
  71.  
  72. def strip(s, chars = None):
  73.     '''strip(s [,chars]) -> string
  74.  
  75.     Return a copy of the string s with leading and trailing
  76.     whitespace removed.
  77.     If chars is given and not None, remove characters in chars instead.
  78.     If chars is unicode, S will be converted to unicode before stripping.
  79.  
  80.     '''
  81.     return s.strip(chars)
  82.  
  83.  
  84. def lstrip(s, chars = None):
  85.     '''lstrip(s [,chars]) -> string
  86.  
  87.     Return a copy of the string s with leading whitespace removed.
  88.     If chars is given and not None, remove characters in chars instead.
  89.  
  90.     '''
  91.     return s.lstrip(chars)
  92.  
  93.  
  94. def rstrip(s, chars = None):
  95.     '''rstrip(s [,chars]) -> string
  96.  
  97.     Return a copy of the string s with trailing whitespace removed.
  98.     If chars is given and not None, remove characters in chars instead.
  99.  
  100.     '''
  101.     return s.rstrip(chars)
  102.  
  103.  
  104. def split(s, sep = None, maxsplit = -1):
  105.     '''split(s [,sep [,maxsplit]]) -> list of strings
  106.  
  107.     Return a list of the words in the string s, using sep as the
  108.     delimiter string.  If maxsplit is given, splits at no more than
  109.     maxsplit places (resulting in at most maxsplit+1 words).  If sep
  110.     is not specified, any whitespace string is a separator.
  111.  
  112.     (split and splitfields are synonymous)
  113.  
  114.     '''
  115.     return s.split(sep, maxsplit)
  116.  
  117. splitfields = split
  118.  
  119. def join(words, sep = ' '):
  120.     '''join(list [,sep]) -> string
  121.  
  122.     Return a string composed of the words in list, with
  123.     intervening occurrences of sep.  The default separator is a
  124.     single space.
  125.  
  126.     (joinfields and join are synonymous)
  127.  
  128.     '''
  129.     return sep.join(words)
  130.  
  131. joinfields = join
  132.  
  133. def index(s, *args):
  134.     '''index(s, sub [,start [,end]]) -> int
  135.  
  136.     Like find but raises ValueError when the substring is not found.
  137.  
  138.     '''
  139.     return s.index(*args)
  140.  
  141.  
  142. def rindex(s, *args):
  143.     '''rindex(s, sub [,start [,end]]) -> int
  144.  
  145.     Like rfind but raises ValueError when the substring is not found.
  146.  
  147.     '''
  148.     return s.rindex(*args)
  149.  
  150.  
  151. def count(s, *args):
  152.     '''count(s, sub[, start[,end]]) -> int
  153.  
  154.     Return the number of occurrences of substring sub in string
  155.     s[start:end].  Optional arguments start and end are
  156.     interpreted as in slice notation.
  157.  
  158.     '''
  159.     return s.count(*args)
  160.  
  161.  
  162. def find(s, *args):
  163.     '''find(s, sub [,start [,end]]) -> in
  164.  
  165.     Return the lowest index in s where substring sub is found,
  166.     such that sub is contained within s[start,end].  Optional
  167.     arguments start and end are interpreted as in slice notation.
  168.  
  169.     Return -1 on failure.
  170.  
  171.     '''
  172.     return s.find(*args)
  173.  
  174.  
  175. def rfind(s, *args):
  176.     '''rfind(s, sub [,start [,end]]) -> int
  177.  
  178.     Return the highest index in s where substring sub is found,
  179.     such that sub is contained within s[start,end].  Optional
  180.     arguments start and end are interpreted as in slice notation.
  181.  
  182.     Return -1 on failure.
  183.  
  184.     '''
  185.     return s.rfind(*args)
  186.  
  187. _float = float
  188. _int = int
  189. _long = long
  190.  
  191. def atof(s):
  192.     '''atof(s) -> float
  193.  
  194.     Return the floating point number represented by the string s.
  195.  
  196.     '''
  197.     return _float(s)
  198.  
  199.  
  200. def atoi(s, base = 10):
  201.     '''atoi(s [,base]) -> int
  202.  
  203.     Return the integer represented by the string s in the given
  204.     base, which defaults to 10.  The string s must consist of one
  205.     or more digits, possibly preceded by a sign.  If base is 0, it
  206.     is chosen from the leading characters of s, 0 for octal, 0x or
  207.     0X for hexadecimal.  If base is 16, a preceding 0x or 0X is
  208.     accepted.
  209.  
  210.     '''
  211.     return _int(s, base)
  212.  
  213.  
  214. def atol(s, base = 10):
  215.     '''atol(s [,base]) -> long
  216.  
  217.     Return the long integer represented by the string s in the
  218.     given base, which defaults to 10.  The string s must consist
  219.     of one or more digits, possibly preceded by a sign.  If base
  220.     is 0, it is chosen from the leading characters of s, 0 for
  221.     octal, 0x or 0X for hexadecimal.  If base is 16, a preceding
  222.     0x or 0X is accepted.  A trailing L or l is not accepted,
  223.     unless base is 0.
  224.  
  225.     '''
  226.     return _long(s, base)
  227.  
  228.  
  229. def ljust(s, width):
  230.     '''ljust(s, width) -> string
  231.  
  232.     Return a left-justified version of s, in a field of the
  233.     specified width, padded with spaces as needed.  The string is
  234.     never truncated.
  235.  
  236.     '''
  237.     return s.ljust(width)
  238.  
  239.  
  240. def rjust(s, width):
  241.     '''rjust(s, width) -> string
  242.  
  243.     Return a right-justified version of s, in a field of the
  244.     specified width, padded with spaces as needed.  The string is
  245.     never truncated.
  246.  
  247.     '''
  248.     return s.rjust(width)
  249.  
  250.  
  251. def center(s, width):
  252.     '''center(s, width) -> string
  253.  
  254.     Return a center version of s, in a field of the specified
  255.     width. padded with spaces as needed.  The string is never
  256.     truncated.
  257.  
  258.     '''
  259.     return s.center(width)
  260.  
  261.  
  262. def zfill(x, width):
  263.     '''zfill(x, width) -> string
  264.  
  265.     Pad a numeric string x with zeros on the left, to fill a field
  266.     of the specified width.  The string x is never truncated.
  267.  
  268.     '''
  269.     if not isinstance(x, basestring):
  270.         x = repr(x)
  271.     
  272.     return x.zfill(width)
  273.  
  274.  
  275. def expandtabs(s, tabsize = 8):
  276.     '''expandtabs(s [,tabsize]) -> string
  277.  
  278.     Return a copy of the string s with all tab characters replaced
  279.     by the appropriate number of spaces, depending on the current
  280.     column, and the tabsize (default 8).
  281.  
  282.     '''
  283.     return s.expandtabs(tabsize)
  284.  
  285.  
  286. def translate(s, table, deletions = ''):
  287.     '''translate(s,table [,deletions]) -> string
  288.  
  289.     Return a copy of the string s, where all characters occurring
  290.     in the optional argument deletions are removed, and the
  291.     remaining characters have been mapped through the given
  292.     translation table, which must be a string of length 256.  The
  293.     deletions argument is not allowed for Unicode strings.
  294.  
  295.     '''
  296.     if deletions:
  297.         return s.translate(table, deletions)
  298.     else:
  299.         return s.translate(table + s[:0])
  300.  
  301.  
  302. def capitalize(s):
  303.     '''capitalize(s) -> string
  304.  
  305.     Return a copy of the string s with only its first character
  306.     capitalized.
  307.  
  308.     '''
  309.     return s.capitalize()
  310.  
  311.  
  312. def capwords(s, sep = None):
  313.     '''capwords(s, [sep]) -> string
  314.  
  315.     Split the argument into words using split, capitalize each
  316.     word using capitalize, and join the capitalized words using
  317.     join. Note that this replaces runs of whitespace characters by
  318.     a single space.
  319.  
  320.     '''
  321.     if not sep:
  322.         pass
  323.     return join(map(capitalize, s.split(sep)), ' ')
  324.  
  325. _idmapL = None
  326.  
  327. def maketrans(fromstr, tostr):
  328.     '''maketrans(frm, to) -> string
  329.  
  330.     Return a translation table (a string of 256 bytes long)
  331.     suitable for use in string.translate.  The strings frm and to
  332.     must be of the same length.
  333.  
  334.     '''
  335.     global _idmapL
  336.     if len(fromstr) != len(tostr):
  337.         raise ValueError, 'maketrans arguments must have same length'
  338.     
  339.     if not _idmapL:
  340.         _idmapL = map(None, _idmap)
  341.     
  342.     L = _idmapL[:]
  343.     fromstr = map(ord, fromstr)
  344.     for i in range(len(fromstr)):
  345.         L[fromstr[i]] = tostr[i]
  346.     
  347.     return join(L, '')
  348.  
  349.  
  350. def replace(s, old, new, maxsplit = -1):
  351.     '''replace (str, old, new[, maxsplit]) -> string
  352.  
  353.     Return a copy of string str with all occurrences of substring
  354.     old replaced by new. If the optional argument maxsplit is
  355.     given, only the first maxsplit occurrences are replaced.
  356.  
  357.     '''
  358.     return s.replace(old, new, maxsplit)
  359.  
  360.  
  361. try:
  362.     from strop import maketrans, lowercase, uppercase, whitespace
  363.     letters = lowercase + uppercase
  364. except ImportError:
  365.     pass
  366.  
  367.